#include <iostream>
#include <queue>
using namespace std;

priority_queue<int, vector<int>, greater<int> > que;

int main()
{
	int n;
	cin >> n;
	for(int  i = 0; i < n; i++)
	{
		int temp;
		cin >> temp;
		que.push(temp);
	}
	int sum  = 0; 
	for(int i= 0 ; i < n-1; i++)
	{
		int x = que.top(); que.pop();
		int y = que.top(); que.pop();
		sum += x+y;
		que.push(x+y);
	}
	cout << sum << endl;
	return 0;
}
